//
//  TuiJianViewController.m
//  lovergotest
//
//  Created by liudonghuan on 14-8-12.
//  Copyright (c) 2014年 liudonghuan. All rights reserved.
//

#import "LGUtil.h"

#import "TuiJianHuoDongViewController.h"
#import "tuijianTitleViewCell.h"
#import "SearchViewController.h"
#define PI 3.1415
@interface TuiJianHuoDongViewController ()
@end
@implementation TuiJianHuoDongViewController
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
//第一次进入初始化同时加载主题页面
-(void)loadView
{
    //初始化静态数据
    _pageNumTuiJian = 1;
    _pageNumHuoDong = 1;
    _whichTable = 0;
    _totalDataleft = [[NSMutableArray alloc]init];
    _totalDataright = [[NSMutableArray alloc]init];
    //根页面及代理
    _tuiJianHuoDongView = [[TuiJianHuoDongView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _tuiJianHuoDongView.scrollView.delegate = self;
    _tuiJianHuoDongView.tableViewleft.delegate = self;
    _tuiJianHuoDongView.tableViewleft.dataSource = self;
    _tuiJianHuoDongView.tableViewright.delegate = self;
    _tuiJianHuoDongView.tableViewright.dataSource = self;
    _tuiJianHuoDongView.tjhdDelegate = self;
    //搜索按钮
    [self addrightBtn];
    [self setupRefresh];
    [_tuiJianHuoDongView.tableViewleft headerBeginRefreshing];
    [self setView:_tuiJianHuoDongView];
}
-(void)addrightBtn
{
    UIButton* rBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,0,18,18)];
    [rBtn setImage:[UIImage imageNamed:@"btn_search_pressed.png"]forState:UIControlStateNormal];
    [rBtn setImage:[UIImage imageNamed:@"btn_search_pressed.png"]forState:UIControlStateHighlighted];
    [rBtn addTarget:self action:@selector(rightBtnclick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithCustomView:rBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
-(void)rightBtnclick{
    SearchViewController *searchViewController = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchViewController animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"barBG_blue.png"] forBarMetrics:UIBarMetricsDefault];
    [MobClick beginLogPageView:@"主页面"];
    
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    //如果在页面离开时不做这些处理，返回的时候会导致fresh往下跑
    [_tuiJianHuoDongView.tableViewleft headerEndRefreshing];
    [_tuiJianHuoDongView.tableViewleft footerEndRefreshing];
    [_tuiJianHuoDongView.tableViewright headerEndRefreshing];
    [_tuiJianHuoDongView.tableViewright footerEndRefreshing];
    [MobClick endLogPageView:@"主页面"];
}
-(void)addToCollection:(TuiJianViewCell *)view//这里执行收藏功能,太长了大神给整整
{
    NSIndexPath *indexPath = [_tuiJianHuoDongView.tableViewleft indexPathForCell:view];
    NSMutableDictionary*  dict = _totalDataleft[indexPath.row];
    NSString *placeUuid = [dict objectForKey:@"placeUuid"];
    NSString *appUserUuid = [[DataCenter getSingleton].userInfo uuid];
    NSString *articleUuid = [dict objectForKey:@"uuid"];
    NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:
                          placeUuid,@"placeUuid",
                          appUserUuid,@"appUserUuid",
                          articleUuid,@"articleUuid",
                          nil];
    if (view.collectStatus == nocollect) {
        if (appUserUuid !=nil) {
            
            [SVHTTPRequest GET:newaddCollection
                    parameters:para
                    completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
                        if (error) {
                            [[[[UIApplication sharedApplication] delegate] window] makeToast:@"网络接连失败"
                                                                                    duration:1.0
                                                                                    position:@"center"];
                        }else{
                            NSError *jsonError = nil;
                            id jsonObject = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&jsonError];
                            int status = [[jsonObject objectForKey:@"status"]intValue];
                            if (status == 0) {
                                view.collectionImage.image = [UIImage imageNamed:@"tuijian_cell_coll_yes.png"];
                                view.collectStatus = hascollect;
                                [[[[UIApplication sharedApplication] delegate] window] makeToast:@"收藏成功"
                                                                                        duration:1.0
                                                                                        position:@"center"];
                                NSString *collectnum = [view.collectionnum text];
                                view.collectionnum.text = [NSString stringWithFormat:@"%d",[collectnum intValue]+1];
                            }else if(status == 3){
                                view.collectionImage.image = [UIImage imageNamed:@"tuijian_cell_coll_yes.png"];
                                view.collectStatus = hascollect;
                                [[[[UIApplication sharedApplication] delegate] window] makeToast:@"再次收藏"
                                                                                        duration:1.0
                                                                                        position:@"center"];
                            }
                            
                        }
                    }];
        }else{
            [[[[UIApplication sharedApplication] delegate] window] makeToast:@"目前收藏功能只对登陆用户开放"
                                                                    duration:1.0
                                                                    position:@"center"];
        }
        
        
    }else if(view.collectStatus == hascollect){
        if (appUserUuid !=nil) {
            [SVHTTPRequest GET:newdecCoolection
                    parameters:para
                    completion:^(id response, NSHTTPURLResponse *urlResponse, NSError *error) {
                        if (error) {
                            [[[[UIApplication sharedApplication] delegate] window] makeToast:@"网络接连失败"
                                                                                    duration:1.0
                                                                                    position:@"center"];
                        }else{
                            NSError *jsonError = nil;
                            id jsonObject = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&jsonError];
                            int status = [[jsonObject objectForKey:@"status"]intValue];
                            if (status == 0) {
                                view.collectionImage.image = [UIImage imageNamed:@"maintab_collect.png"];
                                view.collectStatus = nocollect;
                                [[[[UIApplication sharedApplication] delegate] window] makeToast:@"取消收藏"
                                                                                        duration:1.0
                                                                                        position:@"center"];
                                NSString *collectnum = [view.collectionnum text];
                                view.collectionnum.text = [NSString stringWithFormat:@"%d",[collectnum intValue]-1];
                            }
                            
                        }
                    }];
        }
        
    }else{
        [[[[UIApplication sharedApplication] delegate] window] makeToast:@"目前收藏功能只对登陆用户开放"
                                                                duration:1.0
                                                                position:@"center"];
    }
    
}
//主题活动2个按钮点击后切换界面的事件，0表示按的主题按钮，1表示按的活动按钮
-(void)ChangeViewWith:(TuiJianHuoDongView *)view whichLabel:(whichLabel)which
{
    if (_whichTable == 0) {
        if (which == TuiJianBtn) {
            //当前页上面都不作
        }else if (which == HuoDongBtn){
            if (_totalDataright.count == 0) {
                [_tuiJianHuoDongView.tableViewright headerBeginRefreshing];
            }
            [view.tjBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [view.hdBtn setTitleColor:LGCOLOR_blue forState:UIControlStateNormal];
            [view.tjBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateNormal];
            [view.tjBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateHighlighted];
            [view.hdBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateNormal];
            [view.hdBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateHighlighted];
            _whichTable = 1;
            [_tuiJianHuoDongView.scrollView setContentOffset:CGPointMake(320, 0) animated:YES];
            
        }
    }else if (_whichTable == 1){
        if (which == HuoDongBtn) {
            //当前页面什么都不做
        }else if (which == TuiJianBtn){
            if (_totalDataleft.count == 0) {
                [_tuiJianHuoDongView.tableViewleft headerBeginRefreshing];
            }
            [view.hdBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [view.tjBtn setTitleColor:LGCOLOR_blue forState:UIControlStateNormal];
            [view.hdBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateNormal];
            [view.hdBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateHighlighted];
            [view.tjBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateNormal];
            [view.tjBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateHighlighted];
            _whichTable = 0;
            [_tuiJianHuoDongView.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
            
        }
    }
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float a = _tuiJianHuoDongView.scrollView.contentOffset.x;
    if (scrollView == _tuiJianHuoDongView.scrollView) {
        
        if (a == 320) {
            if (_totalDataright.count == 0) {
                [_tuiJianHuoDongView.tableViewright headerBeginRefreshing];
            }
            [_tuiJianHuoDongView.tjBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.hdBtn setTitleColor:LGCOLOR_blue forState:UIControlStateNormal];
            [_tuiJianHuoDongView.tjBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.tjBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateHighlighted];
            [_tuiJianHuoDongView.hdBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.hdBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateHighlighted];
            _whichTable = 1;
            
        }else if (a == 0){
            if (_totalDataleft.count == 0) {
                [_tuiJianHuoDongView.tableViewleft headerBeginRefreshing];
            }
            [_tuiJianHuoDongView.hdBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.tjBtn setTitleColor:LGCOLOR_blue forState:UIControlStateNormal];
            [_tuiJianHuoDongView.hdBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.hdBtn setBackgroundImage:[UIImage imageNamed:@"barBG.png"] forState:UIControlStateHighlighted];
            [_tuiJianHuoDongView.tjBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateNormal];
            [_tuiJianHuoDongView.tjBtn setBackgroundImage:[UIImage imageNamed:@"firstview_blueline.png"] forState:UIControlStateHighlighted];
            _whichTable = 0;
            
        }
    }
}

#pragma mark - Table view data source and delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 0) {
        return _totalDataleft.count;
    }else{
        return _totalDataright.count;
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView.tag == 0){
        TuiJianViewCell *tcell= [[TuiJianViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        if(_totalDataleft.count < indexPath.row){
            return tcell;
        }
        NSMutableDictionary*  dict = _totalDataleft[indexPath.row];
        if ([[dict objectForKey:@"type"] isEqualToString:@"0"]) {
            NSString *biaoji = [dict objectForKey:@"uuid"];
            TuiJianViewCell *cell = [tableView dequeueReusableCellWithIdentifier:biaoji];
            if (cell == nil) {
                cell = [[TuiJianViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:biaoji];
            }else{
                return cell;
            }
            if ([[dict objectForKey:@"ifCollection"] intValue] == 0) {
                //没收藏
            }else{
                cell.collectionImage.image = [UIImage imageNamed:@"tuijian_cell_coll_yes.png"];
                cell.collectStatus = hascollect;
            }
            NSString *mainimage = [NSString stringWithFormat:@"%@%@%@",imagebaseUrl,baseUploadImages,[dict objectForKey:@"indexImage"]];
            cell.mainimage.imageUrl = mainimage;
            [cell.mainimage.layer setMasksToBounds:YES];
            [cell.mainimage.layer setCornerRadius:2];
            cell.onelabel.text = [dict objectForKey:@"placeName"];
            cell.twolabel.text = [dict objectForKey:@"articleTitle"];
            cell.collectionnum.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"collectionCount"]];
            cell.tjCollectDelegate = self;
            return cell;
            
        }else{
            NSString *biaoti1 = [dict objectForKey:@"uuid"];
            TuiJianTitleViewCell *cell = [tableView dequeueReusableCellWithIdentifier:biaoti1];
            if (cell == nil) {
                cell = [[TuiJianTitleViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                   reuseIdentifier:biaoti1];
            }else{
                return cell;
            }
            
            cell.backgroundColor =[self hexStringToColor:[dict objectForKey:@"backGroundRgb"]];
            NSString *mainimage = [NSString stringWithFormat:@"%@%@%@",imagebaseUrl,baseUploadImagessc,[dict objectForKey:@"indexImage"]];
            cell.righticon.imageUrl = mainimage;
            cell.qishu.text = [dict objectForKey:@"articleTitle"];
            cell.title.text = [dict objectForKey:@"articleIntro"];
            return cell;
        }
        
        
    }else{
        HuoDongViewCell *hcell = [[HuoDongViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                                        reuseIdentifier:nil];
        if (_totalDataright.count < indexPath.row) {
            return hcell;
        }
        NSMutableDictionary*  dict = _totalDataright[indexPath.row];
        NSString *biaoji2 = [dict objectForKey:@"uuid"];
        HuoDongViewCell *cell = [tableView dequeueReusableCellWithIdentifier:biaoji2];
        if (cell == nil) {
            cell = [[HuoDongViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:biaoji2];
        }else{
            return cell;
        }
        NSString *mainimage = [NSString stringWithFormat:@"%@%@%@",imagebaseUrl,baseUploadImages,[dict objectForKey:@"indexImage"]];
        cell.headimage.imageUrl = mainimage;
        [cell.headimage.layer setMasksToBounds:YES];
        [cell.headimage.layer setCornerRadius:2];
        cell.title.text = [NSString stringWithFormat:@"%@%@",@"   ",[dict objectForKey:@"title"]];
        cell.time.text = [NSString stringWithFormat:@"%@%@",@"    ",[dict objectForKey:@"actTime"]];
        if ([[dict objectForKey:@"canJoin"]intValue] == 1) {
            cell.numtitle.text = @"剩余数量";
            cell.num.text = [NSString stringWithFormat:@"%d",[[dict objectForKey:@"activityNum"] intValue]-[[dict objectForKey:@"joinNum"]intValue]];
            cell.num.textColor = LGCOLOR_blue;
        }else{
            cell.numtitle.text = @"即将开放";
            cell.numtitle.textColor = LGCOLOR_blue;
        }
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _tuiJianHuoDongView.tableViewleft) {
        NSMutableDictionary*  dictleft = _totalDataleft[indexPath.row];
        if ([[dictleft objectForKey:@"type"] isEqualToString:@"1"]) {
            return;
        }else{
            NSString *para = [dictleft objectForKey:@"placeUuid"];
            ShangJiaViewController *_shangJiaViewController = [[ShangJiaViewController alloc]initWithDic:para];
            self.navigationItem.backBarButtonItem = [LGUtil getBackButton];
            [self.navigationController pushViewController:_shangJiaViewController animated:YES];
            
        }
        
    }else if(tableView == _tuiJianHuoDongView.tableViewright){
        
        NSDictionary*  dictright = _totalDataright[indexPath.row];
        HuoDongDetailViewController *_huoDongDetailController = [[HuoDongDetailViewController alloc]initWithDic:dictright];
        self.navigationItem.backBarButtonItem = [LGUtil getBackButton];
        [self.navigationController pushViewController:_huoDongDetailController animated:YES];
    }
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 1) {
        return 200;
    }else {
        if (_totalDataleft.count<indexPath.row) {
            return 200;
        }
        NSMutableDictionary*  dict = _totalDataleft[indexPath.row];
        if ([[dict objectForKey:@"type"] isEqualToString:@"0"]) {
            return 200;
        }else{
            return 60;
        }
    }
    
}

/**
 *  集成刷新控件
 */
- (void)setupRefresh
{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tuiJianHuoDongView.tableViewleft addHeaderWithTarget:self action:@selector(headerRereshing)];
    // [_contentView.myTableView headerBeginRefreshing];
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [_tuiJianHuoDongView.tableViewleft addFooterWithTarget:self action:@selector(footerRereshing)];
    
    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    _tuiJianHuoDongView.tableViewleft.headerPullToRefreshText = @"下拉可以刷新了";
    _tuiJianHuoDongView.tableViewleft.headerReleaseToRefreshText = @"松开马上知道去哪儿";
    _tuiJianHuoDongView.tableViewleft.headerRefreshingText = @"今天情侣去哪儿呢？";
    
    _tuiJianHuoDongView.tableViewleft.footerPullToRefreshText = @"上拉加载数据";
    _tuiJianHuoDongView.tableViewleft.footerReleaseToRefreshText = @"松开马上知道去哪儿";
    _tuiJianHuoDongView.tableViewleft.footerRefreshingText = @"今天情侣去哪儿呢？";
    
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tuiJianHuoDongView.tableViewright addHeaderWithTarget:self action:@selector(headerRereshing)];
    // [_contentView.myTableView headerBeginRefreshing];
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [_tuiJianHuoDongView.tableViewright addFooterWithTarget:self action:@selector(footerRereshing)];
    
    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    _tuiJianHuoDongView.tableViewright.headerPullToRefreshText = @"下拉可以刷新了";
    _tuiJianHuoDongView.tableViewright.headerReleaseToRefreshText = @"松开马上知道去哪儿";
    _tuiJianHuoDongView.tableViewright.headerRefreshingText = @"今天情侣去哪儿呢?";
    
    _tuiJianHuoDongView.tableViewright.footerPullToRefreshText = @"上拉加载数据";
    _tuiJianHuoDongView.tableViewright.footerReleaseToRefreshText = @"松开马上知道去哪儿";
    _tuiJianHuoDongView.tableViewright.footerRefreshingText = @"今天情侣去哪儿呢?";
}
#pragma mark 开始进入刷新状态
- (void)headerRereshing
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (_whichTable == 0) {
            _pageNumTuiJian = 1;
            [self startRequest:[NSString stringWithFormat:@"%d",_pageNumTuiJian] Flag:0];
        }else if(_whichTable == 1){
            _pageNumHuoDong = 1;
            [self startRequest:[NSString stringWithFormat:@"%d",_pageNumHuoDong] Flag:0];
        }
        
    });
    
}

- (void)footerRereshing
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (_whichTable == 0) {
            _pageNumTuiJian = _pageNumTuiJian+1;
            [self startRequest:[NSString stringWithFormat:@"%d",_pageNumTuiJian] Flag:1];
        }else if (_whichTable == 1){
            _pageNumHuoDong = _pageNumHuoDong+1;
            [self startRequest:[NSString stringWithFormat:@"%d",_pageNumHuoDong] Flag:1];
        }
    });
}
/*
 * 开始请求Web Service
 */
-(void)startRequest:(NSString *)page Flag:(int)flag
{
    UserInfo *info = [[DataCenter getSingleton] userInfo];
    NSString *uuid;
    if (_whichTable == 0 ) {
        if (info.uuid!=nil) {
            uuid = info.uuid;
        }else{
            uuid = @"";
        }
        NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:
                              uuid,@"appUserUuid",
                              @"tj",@"city",
                              page,@"page",
                              nil];
        [[RequestManager getSingleton] sendRequest:findArticleByCity para:para callBack:^(id responseObj) {
            [self loadData:responseObj Flag:flag];
        }];
    }
    else{
        NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"tj",@"city",
                              page,@"page",
                              nil];
        [[RequestManager getSingleton] sendRequest:findActivityByCity para:para callBack:^(id responseObj) {
            [self loadData:responseObj Flag:flag];
            
        }];
    }
    [_tuiJianHuoDongView.tableViewleft  footerEndRefreshing];
    [_tuiJianHuoDongView.tableViewleft  headerEndRefreshing];
    [_tuiJianHuoDongView.tableViewright headerEndRefreshing];
    [_tuiJianHuoDongView.tableViewright footerEndRefreshing];
}
-(void)loadData:(NSDictionary*)res Flag:(int)flag
{
    if (_whichTable == 0) {
        if (flag == 0) {//头部刷新
            [_totalDataleft removeAllObjects];
            _listDataleft =[res objectForKey:@"data"];
            [_totalDataleft addObjectsFromArray:_listDataleft];
            [_tuiJianHuoDongView.tableViewleft reloadData];
        }else{
            if(_listDataleft.count == 0) {
                _pageNumTuiJian = _pageNumTuiJian-1;
            }else{
                _listDataleft =[res objectForKey:@"data"];
                [_totalDataleft addObjectsFromArray:_listDataleft];
                [_tuiJianHuoDongView.tableViewleft reloadData];
            }
        }
    }else if (_whichTable == 1){
        if (flag == 0) {//头部刷新
            [_totalDataright removeAllObjects];
            _listDataright =[res objectForKey:@"data"];
            [_totalDataright addObjectsFromArray:_listDataright];
            [_tuiJianHuoDongView.tableViewright reloadData];
        }else{
            if(_listDataleft.count == 0) {
                _pageNumHuoDong = _pageNumHuoDong-1;
            }else{
                _listDataright =[res objectForKey:@"data"];
                [_totalDataright addObjectsFromArray:_listDataright];
                [_tuiJianHuoDongView.tableViewright reloadData];
            }
        }
    }
    
    
    
}
//16进制转换
-(UIColor *) hexStringToColor: (NSString *) stringToConvert
{
    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    // String should be 6 or 8 charactersif ([cString length] < 6) return [UIColor blackColor];
    // strip 0X if it appearsif ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
    if ([cString length] != 6) return [UIColor grayColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    // Scan values
    unsigned int r, g, b;
    
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:1.0f];
}


@end